<?php
namespace app\admin\controller;
use app\admin\Controller;
use think\Db;
use think\Request;
class Activity extends Controller
{
    use \app\admin\traits\controller\Controller;
    // 方法黑名单
    protected static $blacklist = [];
    public function add()
    {
        return view();
    }
    public function insert(Request $request)
    {
        $data =$request->param();
        //5M
        $size = 1024*1024*20;
        $format = ['jpg','png'];
        $image = $this->request->file('image_src');
        $file_info = Common::doFileData($image,$size,$format,'image_src');
        unset($file_info['size']);
        unset($file_info['format']);
        $data = array_merge($data,$file_info);
        $data['create_time'] = time();
        if (Db::name('activity')->insert($data)) {
            return ajax_return_adv('成功！','1');
        } else {
            return ajax_return_adv('失败！','0');
        }
    }
    public function update(Request $request)
    {
        $data =$request->param();
        //5M
        $size = 1024*1024*20;
        $format = ['jpg','png'];
        $image = $this->request->file('image_src');
        if($image!=null)
        {
            $file_info = Common::doFileData($image,$size,$format,'image_src');
            unset($file_info['size']);
            unset($file_info['format']);
            $data = array_merge($data,$file_info);
        }
        $data['create_time'] = time();
        if (Db::name('activity')->update($data)) {
            return ajax_return_adv('成功！','1');
        } else {
            return ajax_return_adv('失败！','0');}
    }
    

    
}
